package cn.zdm.designpattern.chainpattern;

/**
 * copyright (C), 2020, 北京同创永益科技发展有限公司
 *
 * @author ZhaoDeman
 * @version 1.0.0
 * <author>                <time>                  <version>                   <description>
 * ZhaoDeman        2020/12/4 17:20                 1.0
 * @Program designpattern
 * @Description
 * @Create 2020/12/4 17:20
 */
public abstract class AbstractLogger {
    public static int INFO = 0;
    public static int DEBUG = 1;
    public static int ERROR = 2;
    protected int level;
    protected AbstractLogger nextLogger;

    public void setNextLogger(AbstractLogger abstractLogger) {
        this.nextLogger = abstractLogger;
    }

    public void logMessage(int level, String message) {
        if (this.level <= level) {
            write(message);
        }
        if (nextLogger != null) {
            nextLogger.logMessage(level, message);
        }
    }

    /**
     * 打印错误信息
     *
     * @param message 错误信息
     * @return void
     * @date 2020/12/4 17:30
     */
    abstract protected void write(String message);
}
